package com.wxzz.elearing.user.api.app;


import com.alibaba.fastjson.JSONObject;
import com.wxzz.elearing.user.dto.SubToolFormDelDto;
import com.wxzz.elearing.user.dto.SubToolFormDto;
import com.wxzz.elearing.user.entity.SubToolForm;
import com.wxzz.elearing.user.service.ISubToolFormService;
import com.wxzz.elearning.common.vo.JgPageVo;
import com.wxzz.elearning.common.vo.ReturnVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.io.IOException;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 
 * @since 2021-05-18
 */
@RestController
@RequestMapping("/wx-sub-tool-form")
@Api(tags = "二级工具表单(小程序)")
public class WxSubToolFormController {

    @Autowired
    private RedisTemplate<String,String> redisTemplate;

    @Resource
    private ISubToolFormService iSubToolFormService;

//    @ApiOperation(value = "添加二级工具表单(后台)", notes = "添加二级工具表单(后台)", httpMethod = "POST", tags = "后台")
//    @RequestMapping(value = "addToolForm", method = RequestMethod.POST)
//    public ReturnVO addToolForm(@RequestBody SubToolForm toolForm, @RequestHeader String token) throws IOException {
//        JSONObject jsonObject = JSONObject.parseObject(redisTemplate.opsForValue().get(token));
//        toolForm.setAdminUserId(jsonObject.getLong("id"));
//        toolForm.setEnterpriseId(jsonObject.getLong("enterpriseId"));
//        return iSubToolFormService.addSubToolForm(toolForm);
//    }

    @ApiOperation(value = "二级工具表单列表(小程序)", notes = "二级工具表单列表(小程序)", httpMethod = "POST", tags = "小程序")
    @RequestMapping(value = "SubToolFormList", method = RequestMethod.POST)
    public ReturnVO<JgPageVo<List<SubToolForm>>> toolFormList(@RequestBody SubToolFormDto toolFormDto, @RequestHeader String token) throws IOException {
        JSONObject jsonObject = JSONObject.parseObject(redisTemplate.opsForValue().get(token));
        toolFormDto.setEnterpriseId(jsonObject.getLong("enterpriseId"));
        return iSubToolFormService.subToolFormList(toolFormDto);
    }

//    @ApiOperation(value = "删除二级工具表单(后台)", notes = "删除二级工具表单(后台)", httpMethod = "POST", tags = "后台")
//    @RequestMapping(value = "deleteSubToolForm", method = RequestMethod.POST)
//    public ReturnVO deleteSubToolForm(@RequestHeader String token, @RequestBody SubToolFormDelDto toolForm) {
////        JSONObject jsonObject = JSONObject.parseObject(redisTemplate.opsForValue().get(token));
////        adminWorkGuideline.setCreatePerson(jsonObject.getLong("enterpriseId"));
////        adminWorkGuideline.setCreatePerson(jsonObject.getString("nickname"));
//        return iSubToolFormService.deleteSubToolForm(toolForm);
//    }
}
